/*
 * Project: Digital Wristwatch
 * Author: Zak Kemble, contact@zakkemble.co.uk
 * Copyright: (C) 2013 by Zak Kemble
 * License: GNU GPL v3 (see License.txt)
 * Web: http://blog.zakkemble.co.uk/diy-digital-wristwatch/
 */

#include <avr/eeprom.h>
#include "common.h"
#include "watchconfig.h"

s_watchconfig watchConfig;

static const s_watchconfig eepConfig EEMEM = {
	0x55,
	2,	//10S
	false,
	true,
	false,
	false,
	true,
	{
		255
	}
};

static void load(void);
static void save(void);

void watchconfig_init()
{
	load();
}

void watchconfig_default()
{
	watchConfig.inited_flag = 0x55;
	watchConfig.sleepTimeout = 2;
	watchConfig.invert = false;
	watchConfig.animations = true;
	watchConfig.display180 = false;
	watchConfig.acceleration = true;
	watchConfig.showFPS = false;
	watchConfig.volumes = 0x4C;
}
static void load()
{
	byte inited_flag = 0;

	eeprom_read_block(&inited_flag, &eepConfig.inited_flag, 1);
	if(inited_flag == 0x55) {
		eeprom_read_block(&watchConfig, &eepConfig, sizeof(s_watchconfig));
	} else {
		watchconfig_default();
	}
}

static void save()
{
	eeprom_update_block(&watchConfig, (s_watchconfig*)&eepConfig, sizeof(s_watchconfig));
}

void watchconfig_save()
{
	save();
}